package com.aat.high.json;

import com.aat.high.orm.bean.User;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonTest {

	public static void main(String[] args) {
		User u = new User();
		u.setId("1");
		u.setAccount("admin");
		u.setNickname("张三");

	}

	public static void fastjson(User u) {
		Long l1=System.currentTimeMillis();
		String s = JSON.toJSONString(u);
		System.out.println(s);
		User uj1 = JSON.parseObject(s, User.class);
		System.out.println(uj1.getAccount());
		Long l2=System.currentTimeMillis();
		System.out.println(l2-l1);
	}
	
	public static void jackson(User u) throws Exception {
		Long l1=System.currentTimeMillis();
		ObjectMapper objMapper=new ObjectMapper();
		JsonGenerator JsonGenerator=objMapper.getFactory().createGenerator(System.out, JsonEncoding.UTF8);
		JsonGenerator.writeObject(u);
		Long l2=System.currentTimeMillis();
		System.out.println(l2-l1);
	}

}
